import { defineStore } from "pinia";
import request from '@/utils/request'
import { ApiRes, BannerItem, BrandItem, GoodsItem, HotItem, ProductItem, Special } from "@/types/data";

// 复制后记得修改 name
export default defineStore('home', {
  state: () => ({
    bannerList: [] as BannerItem[],
    newGoodsList: [] as GoodsItem[],
    hotGoodsList: [] as HotItem[],
    brandList: [] as BrandItem[],
    productList: [] as ProductItem[],
    specialList: [] as Special[]
  }),
  actions: {
    async getBannerList() {
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      // console.log(res)
      this.bannerList = res.data.result
    },
    async getHomeNew() {
      const res = await request.get<ApiRes<GoodsItem[]>>('/home/new')
      this.newGoodsList = res.data.result
    },
    async getHomeHot() {
      const res = await request.get<ApiRes<HotItem[]>>('/home/hot')
      this.hotGoodsList = res.data.result
    },
    async getBrandList() {
      const res = await request.get<ApiRes<BrandItem[]>>('/home/brand')
      console.log(res)
      this.brandList = res.data.result
    },
    async getProductList() {
      const res = await request.get<ApiRes<ProductItem[]>>('/home/goods')
      this.productList = res.data.result
    },
    async getSpecialList() {
      const res = await request.get<ApiRes<Special[]>>('/home/special')
      this.specialList = res.data.result
    },
  },
  getters: {}
})